package com.client;

import java.awt.Graphics;

import javax.swing.JPanel;

@SuppressWarnings("serial")
public class DrawArea extends JPanel {
	private Monitor	m;
	private String	s;
	private int		topPos, height;
	private Thread	refresher;

	public DrawArea(Monitor m, int height, String s)
	{
		this.m = m;
		this.height = height;
		topPos = 0;
		this.s = s;
		start();
	}

	public void start()
	{
		refresher = new UpdateDrawThread(this);
		refresher.start();
	}

	public void stop()
	{
		refresher = null;
	}

	public void paint(Graphics g)
	{
		update(g);
	}

	public void update(Graphics g)
	{
		if (s != null)
		{
			g.drawString(s, 10, 10);
		} else
		{
			// Graphics2D g2 = (Graphics2D) g;
			// g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
			// RenderingHints.VALUE_ANTIALIAS_ON);
			g.drawImage(m.getImage(), 0, topPos, this);
		}
	}

	public void setTopPosition(int delta)
	{
		topPos += delta;
		if (topPos > 0)
		{
			topPos = 0;
		}
		int allowOutSide = height - getSize().height;
		if (topPos + allowOutSide < 0)
		{
			topPos = -allowOutSide;
		}
	}

	public int getTopPosition()
	{
		return topPos;
	}

}
